package com.fjwt.gz.task.fans;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.fjwt.gz.service.impl.FansUserService;
import com.fjwt.gz.service.impl.StatMemberInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 同步小程序用户
 */

@Slf4j
@Component
public class FansUserSyncTask {
    @Autowired
    private FansUserService fansUserService;

    @Autowired
    private StatMemberInfoService memberInfoService;

    // @Scheduled(cron = "${cron.MemberInfoSyncTask}")
    public void start() {
        // 获取昨天的日期
        String time = DateUtil.format(DateUtil.yesterday(), DatePattern.PURE_DATE_PATTERN);
        // 查询是否存在记录
        long count = memberInfoService.count();
        // 同步小程序用户信息
        if(0 == count){
            memberInfoService.getBaseMapper().saveMemberInfo(null);
        }else{
            memberInfoService.getBaseMapper().saveMemberInfo(time);
        }
        // 同步用户所归属机构信息
        memberInfoService.getBaseMapper().updateMemberInfoAgent();
        // 同步实名认证信息
        memberInfoService.getBaseMapper().updateMemberInfoAuth();
    }
}
